<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="java.util.*,util.*,dal.*,model.*,bll.*"%>
<%
	QuotationModel obj;
	Object temp = request.getAttribute("quotation");
	if (temp != null) {
		try {
			obj = (QuotationModel) temp;
		} catch (Exception ex) {
			obj = new QuotationModel();
		}
	} else {
		obj = new QuotationModel();
	}
	int idProject = obj.getIdProject();
	String projectName = CacheUtil.getProjectName(idProject);
	String projectUrl = "project.jsp?id="+idProject;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Edit Quotation</title>
<link rel="stylesheet" href="css/common.css" />
<link rel="stylesheet" href="css/inputForm.css" />
<link rel="stylesheet" href="css/listForm.css" />
<link rel="stylesheet" href="css/jquery-ui-1.8.14.custom.css" type="text/css" />
<link rel="stylesheet" href="css/hyjack.css" type="text/css" />
<link rel="stylesheet" href="css/datepicker.css" type="text/css" />
<link rel="stylesheet" href="css/themes/ui-lightness/jquery.ui.all.css" />
<link rel="stylesheet" href="css/jquery-ui-timepicker.css" type="text/css" />
<link rel="stylesheet" href="css/jquery-datepicker.css" />
<link rel="stylesheet" href="css/jquery-dialog.css" />

<script language="javascript" type="text/javascript" src="js/jquery.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.select.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.core.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.widget.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.timepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/datepicker.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.hyjack.js"></script>
<script language="javascript" type="text/javascript" src="js/ajaxQuickInsert.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.ui.tools.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.numeric.js"></script>
<script language="javascript" type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-timepicker-addon.js"></script>
<script language="javascript" type="text/javascript">

	$(document).ready(pagedLoaed);
	
	function pagedLoaed()
	{
		turnOnNumbericInput();

		initDatePicker();
		initTooltip();	
	}
	var requiredInputs = [['name','name_required'],['management_fee','management_fee_required'],['vat_rate','vat_rate_required']];
	var intInputs = [];
	var doubleInputs = [];
	var dateInputs = [['issue_date_date', 'issue_date_date_invalid']];
	var timeInputs = [];

	function checkInputs() {
		var valid = true;

		if (checkRequiredInputs(requiredInputs) == false) {
			valid = false;
		}
		if (checkIntInputs(intInputs) == false) {
			valid = false;
		}
		if (checkDoubleInputs(doubleInputs) == false) {
			valid = false;
		}
		if (checkDateInputsForCorrectedFormatOnly(dateInputs, dateFormat) == false) {
			valid = false;
		}
		if (checkTimeInputs(timeInputs) == false) {
			valid = false;
		}

		// SPECIFIC VALIDATE CODE HERE		

		return valid;
	}
</script>
</head>
<body>
	<div class="divContainer">
		<%@ include file="menu.jsp"%>
				<form id="inputForm" action="quotation?mode=update&id_project=<%=idProject %>" method="post" onSubmit="return checkInputs()" onreset="return confirm('Do you really want to reset the form?')">
					<table class="tblInput">
						<tr><td colspan="1">
							<b>Project:
								<a id="link_project" name="link_project" href="<%=projectUrl %>"><%=projectName %></a>
							</b>	
						</td></tr>
						<tr>
							<td class="inputHeader">EDIT QUOTATION</td>
						</tr>
						<tr>
					<td style="padding-left: 200px; padding-right: 200px;">
						<table cellspacing="0px">
						<tr class="trField">
							<td class="tdFieldName">Id</td>
							<td class="tdFieldInput">
								<input class="inputInt readonly" type="text" id="id" name="id" readonly="readonly" title="The id of this quotation. It's readonly."
									value="<%=obj.getId()%>" />
							</td>
							<td class="tdErrMsg"></td>
							<td style="width: 30px;" rowspan="7" ></td>

							<td class="tdFieldName">Total</td>
							<td class="tdFieldInput">
								<input class="inputNumeric" type="text" id="total" name="total" maxlength="20" 
									value="<%=obj.getTotalToString()%>" title="Total of quotation." tabindex="8"/>

							</td>
							<td class="tdErrMsg">
							</td>					
						<tr class="trField">
							<td class="tdFieldName">Name</td>
							<td class="tdFieldInput">
								<input class="inputText" type="text" id="name" name="name" maxlength="255" title="Name of quotation. Note: It's required." 
									tabindex="1" value="<%=obj.getNameToString()%>" onblur="validateRequiredInput('name');"/>
							</td>
							<td class="tdErrMsg">
								<span id="name_required" class="errMsg" style="display: none;" title="Name is a required field. You have to enter value into it.">(!)</span> 
<!-- 								<span id="name_invalid" class="errMsg" style="display: none;">(!)</span>  -->
								<span id="name_error" class="errMsg"><%=obj.errMsgs.Name%></span>
							</td>			
							
							<td class="tdFieldName">VAT Rate</td>
							<td class="tdFieldInput">
								<input class="inputNumeric" type="text" id="vat_rate" name="vat_rate" maxlength="20" 
									tabindex="9" value="<%=obj.getVatRateToString()%>" title="VAT rate for the quotation. Note: Required."  onblur="validateRequiredInput('vat_rate');"/>
							</td>
							<td class="tdErrMsg">
								<span id="vat_rate_required" class="errMsg" style="display: none;" title="VAT rate is a required field. You have enter into it a value.">(!)</span>
								<span id="vat_rate_invalid" class="errMsg" style="display: none;">(!)</span>
								<span id="vat_rate_error" class="errMsg"><%=obj.errMsgs.VatRate%></span>
							</td>							
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Date of issue</td>
							<td class="tdFieldInput">
								<input type="text" maxlength="10" class="inputDate" id="issue_date_date" name="issue_date_date" onchange="validateDateInput('issue_date_date',false)"
									tabindex="2" value="<%=StringUtil.toDateString(obj.getIssueDate())%>" title="Click to choose date of issue." />	
								<span class="textGuide">(dd/mm/yyyy)</span>							
							</td>
							<td class="tdErrMsg">
								<span id="issue_date_date_required" class="errMsg" style="display: none;" title=" ">(!)</span> 
								<span id="issue_date_date_invalid" class="errMsg" style="display: none;" title="You've entered invalid date!">(!)</span>
								<span id="issue_date_date_error" class="errMsg" style="display: none;"><%=obj.errMsgs.IssueDate %></span>
							</td>
							
							<td class="tdFieldName">Management Fee (%)</td>
							<td class="tdFieldInput">
								<input class="inputNumeric" type="text" id="management_fee" name="management_fee" maxlength="20" 
									tabindex="10" value="<%=obj.getManagementFeeToString()%>" title="Management fee for the quotation. Note: It's required."  onblur="validateRequiredInput('management_fee');"/>

							</td>
							<td class="tdErrMsg">
								<span id="management_fee_required" class="errMsg" style="display: none;" title="Management fee is a required field. You have to enter into it a value.">(!)</span> 
								<span id="management_fee_invalid" class="errMsg" style="display: none;">(!)</span> 
								<span id="management_fee_error" class="errMsg"><%=obj.errMsgs.ManagementFee%></span>
							</td>
						</tr>					
						<tr class="trField">
							<td class="tdFieldName">Prepared by</td>
							<td class="tdFieldInput">
								<select id="id_author" name="id_author" class="hyjack" tabindex="3" >
									<%=HtmlUtil.<EmployeeModel> genModelSelect(CacheUtil.getEmployeeList(), null, obj.getIdAuthor())%>
								</select>
								<input class="btnAdd" type="button" id="addNewAuthor" value="" tabindex="4" title="Click to add new employee"
									 onclick="ajaxAddItemTwoSelectors('#id_author', '#id_approver', 'employee', 'name', 'Please enter new author name!');" />
							</td>
							<td class="tdErrMsg"></td>														
							
							<td class="tdFieldName">Grand Total</td>
							<td class="tdFieldInput">
								<input class="inputNumeric" type="text" id="grand_total" name="grand_total" maxlength="20" 
									tabindex="11" value="<%=obj.getGrandTotalToString()%>" title="Grand of total for this quotation. Note: Numeric only" />

							</td>
							<td class="tdErrMsg">	
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Approved by</td>
							<td class="tdFieldInput">
								<select id="id_approver" name="id_approver" class="hyjack" tabindex="5" >
									<%=HtmlUtil.<EmployeeModel> genModelSelect(CacheUtil.getEmployeeList(), null, obj.getIdApprover(), false, true)%>
								</select>
								<input class="btnAdd" type="button" id="addNewApproval" value="" tabindex="6" title="Click to add new employee."
									onclick="ajaxAddItemTwoSelectors('#id_approver', '#id_author', 'employee', 'name', 'Please enter new approval name!');" />
							</td>
							<td class="tdErrMsg"></td>													
							
							<td class="tdFieldName">Status</td>
							<td class="tdFieldInput">
								<select id="status" name="status" class="hyjack" tabindex="12" title="Choose one status">
									<%=HtmlUtil.genEnumSelect(EnumName.QuotationStatus, null, obj.getStatus())%>
								</select>

							</td>
							<td class="tdErrMsg">
								
							</td>
						</tr>
						<tr class="trField">
							<td class="tdFieldName">Description</td>
							<td class="tdFieldInput">
								<textarea id="description" name="description" rows="5" class="inputTextarea" title="Descriptiion for the quotation"
									tabindex="7"  ><%=obj.getDescription()%></textarea>
							</td>
							<td class="tdErrMsg">
								
							</td>
							
							<td class="tdFieldName">Remark</td>
							<td class="tdFieldInput">
								<textarea id="remark" name="remark" rows="5" class="inputTextarea" tabindex="13"  title="Enter remark for this quotation."><%=obj.getRemark()%></textarea>
							</td>
							<td class="tdErrMsg">
								
							</td>		
						</tr>						
						<tr class="trInputBottom">
							<td class="tdInputBottom" colspan="6"><input class="btnSubmit" type="submit" value="Submit" tabindex="14" title="Click to save."/></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</form>
	<%
		String urlQuotationList = "quotationList.jsp?embedded=true";
		if(idProject != 0)
			urlQuotationList += "&idProject="+idProject;
	%>
	<jsp:include page='<%=urlQuotationList%>'></jsp:include>
	</div>
</body>
</html>